<?php
namespace app\index\controller;

use app\common\controller\Front;

class Image extends Front
{
    protected function initialize()
    {
        $this->auth['check'] = true;
        
        $this->auth['cancel_login'] = ['index/image/index'];
        
        $this->auth['cancel_limit'] = '*';

        $this->auth['redirect_url'] = dcUrl('index/image/index');
        
        parent::initialize();
    }

    public function index()
    {
        $this->site['historyGo'] = dcUrl('index/index/index');
        
        $this->assign(config('image.'));

        $this->assign($this->site);

        return $this->fetch();
    }

    public function save()
    {
        //积分验证
        if(config('image.score')){
            $this->scoreValidate(config('image.score'));
        }
        //解析接口
        $post = input('request.post/a');
        $json = model('index/Douyin','loglic')->init($post['text']);
        if(!$json){
            $this->error(model('index/Douyin','loglic')->getError());
        }
        //积分扣除
        if(config('image.score')){
            model('common/Score','loglic')->decApps($this->user['user_id'], config('image.id'), config('image.score'), config('image.name'));
        }
        $this->success('ok','index/image/index',['desc'=>$json['title'],'audio'=>$json['music'],'images'=>$json['images']]);
    }
}